/*
* @ author madman 
* @ use 数据库连接
*/
const mongoose = require('mongoose');
const config = require('../../config/config');

const dbConfig = config[process.env.NODE_ENV || 'development'];

const db = mongoose.connect(dbConfig.mongo.uri,{useMongoClient:true});
mongoose.Promise = global.Promise;

// 连接成功 
db.on('connected', function () {
  console.log('Mongoose connection open to ' + dbConfig.mongo.uri);
});

// 连接失败
db.on('error', function (err) {
  console.log('Mongoose connection error: ' + err);
});

// 断开连接
db.on('disconnected', function () {
  console.log('Mongoose connection disconnected');
});

